import { defineConfig, loadEnv, ConfigEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import inject from "@rollup/plugin-inject"
import path from "path";

// https://vitejs.dev/config/
export default defineConfig(({ mode } : ConfigEnv) => {
  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [
      vue(),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
        symbolId: 'icon-[dir]-[name]'
      }),
      inject({
        $: "jquery", // 这里会自动载入 node_modules 中的 jquery jquery全局变量
        jQuery: "jquery",
        "windows.jQuery": "jquery"
      })
    ],
    server: {
      host: "0.0.0.0",
      port: 80,
      proxy: {
        [env.VITE_APP_BASE_API]: {
          target: `http://127.0.0.1:7002`,// http://127.0.0.1:8001
          changeOrigin: true,
          rewrite: (path) => path.replace(env.VITE_APP_BASE_API, '')
        }
      }
    },
    css: {
      preprocessorOptions: {
        less: {
          // 这里可以设置全局LESS变量等
        }
      }
    },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, "./src")
      }
    }
  }
})
